package everyday;

import java.util.PriorityQueue;

/**
 * @Author: Siantar
 * @Date: 2023-06-07-15:12
 * @Description: 1.0
 */
public class T2611 {
    public int miceAndCheese(int[] reward1, int[] reward2, int k) {
        int ans = 0;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((a, b) -> a - b);
        for (int i = 0; i < reward1.length; i++) {
            ans += reward2[i];
            priorityQueue.offer(reward1[i]-reward2[i]);
            if (priorityQueue.size()>k){
                priorityQueue.poll();
            }
        }
        while(!priorityQueue.isEmpty()){
            ans+=priorityQueue.poll();
        }
        return ans;
    }
}
